#ifndef _AVLSRCH_DEF
#define _AVLSRCH_DEF

struct avlbind
{
	struct avlbind *left;
	struct avlbind *right;
	int balance;
} __attribute__ ((packed));

struct avltree
{
#ifdef AVL_NO_TREE_PARAM
	int (*compare_key)(struct avlbind *node);
#else
	int (*compare_key_tree)(struct avltree *tree, struct avlbind *node);
#endif
	struct avlbind *root;
	unsigned long num_nodes;
};

struct avlsearch
{
	struct avlbind **path_taken[40];
	int dir_taken[40];
	int current_level;
	struct avlbind **current_node;
};

int avl_insert(struct avltree *tree, struct avlbind *node);
struct avlbind *avl_delete(struct avltree *tree);

struct avlbind *avl_get_first(struct avltree *tree, struct avlsearch *search);
struct avlbind *avl_get_last(struct avltree *tree, struct avlsearch *search);
struct avlbind *avl_get_next(struct avlsearch *search);
struct avlbind *avl_get_prev(struct avlsearch *search);
struct avlbind *avl_get_less(struct avltree *tree, struct avlsearch *search);
struct avlbind *avl_get_less_equal(struct avltree *tree, struct avlsearch *search);
struct avlbind *avl_get_greater(struct avltree *tree, struct avlsearch *search);
struct avlbind *avl_get_greater_equal(struct avltree *tree, struct avlsearch *search);

struct avlbind *avl_delete_current(struct avltree *tree, struct avlsearch *search);

unsigned IsAVL(struct avltree *tree);
void PrintTree(struct avlbind *node, unsigned level);
void PrintSearch(struct avlsearch *search);
struct avlbind *avl_search(struct avltree *tree, struct avlsearch *search);
#endif
